package com.gz3;

import java.awt.*;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getLocalHost(), 9999);

       String filepath="E:\\Java\\java_code\\pictur_reserve\\picture.gif";
        OutputStream outputStream = socket.getOutputStream();
       FileInputStream fileInputStream = new FileInputStream(filepath);
       BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
       byte[] buffer = new byte[1024];
       int byteslen;
       while ((byteslen = bufferedInputStream.read(buffer)) != -1) {
           outputStream.write(buffer, 0, byteslen);
       }
        socket.shutdownOutput();//注意！！！这里是socket.getOutputStream()
                                //一定要写，否则下面的都没用


        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s = bufferedReader.readLine();
        System.out.println(s);

        //关闭
        bufferedReader.close();
       outputStream.flush();
       bufferedInputStream.close();
       socket.close();
       outputStream.close();//关闭顺序无所谓




    }
}
